package com.swak.json;

import java.util.List;

import com.google.common.collect.Lists;
import com.swak.utils.JsonMapper;

/**
 * Json 的测试
 * 
 * @author lifeng
 * @date 2020年5月12日 下午5:08:44
 */
public class JsonMain {

	public static void main(String[] args) {
		System.out.println("StringOrder。。。。。。。。。。。。");
		StringOrder sorder = new StringOrder();
		sorder.setId("1024");
		sorder.setName2("哈哈的订单");
		sorder.setPk2("pk2");
		sorder.setPk3("pk3");
		String sjson = JsonMapper.toJson(sorder);
		System.out.println(sjson);
		StringOrder sorder2 = JsonMapper.fromJson(sjson, StringOrder.class);
		System.out
				.println(sorder2.getId() + ":" + sorder2.getName2() + ":" + sorder2.getPk2() + ":" + sorder2.getPk3());

		System.out.println("LongOrder。。。。。。。。。。。。");
		LongOrder lorder = new LongOrder();
		lorder.setId(1024L);
		String ljson = JsonMapper.toJson(lorder);
		System.out.println(ljson);
		LongOrder lorder2 = JsonMapper.fromJson(ljson, LongOrder.class);
		System.out.println(lorder2.getId());

		System.out.println("泛型类测试。。。。。。。。。。。。");
		GenEntity<Long, String> genEntity = new GenEntity<>();
		genEntity.setPk2("PK2");
		System.out.println(JsonMapper.toJson(genEntity));

		System.out.println("List 泛型类测试。。。。。。。。。。。。");
		List<LongOrder> orders = Lists.newArrayList();
		LongOrder lo1 = new LongOrder();
		lo1.setId(1L);
		orders.add(lo1);
		lo1 = new LongOrder();
		lo1.setId(2L);
		orders.add(lo1);
		System.out.println(JsonMapper.toJson(orders));

		orders = JsonMapper.fromJsonToList(JsonMapper.toJson(orders), LongOrder.class);
		for (LongOrder order : orders) {
			System.out.println(order.getId());
		}

		System.out.println("OrderList 测试。。。。。。。。。。。。");
		OrderList orderList = OrderList.build();
		System.out.println(JsonMapper.toJson(orderList));
		System.out.println(JsonMapper.fromJson(JsonMapper.toJson(orderList), OrderList.class));
		orderList = JsonMapper.fromJson(JsonMapper.toJson(orderList), OrderList.class);
		System.out.println(orderList.getOrders().get(0).getName2());
	}
}
